package com.jscq.yygh.user.service.impl;

import com.alibaba.excel.util.StringUtils;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.enums.DictEnum;
import com.atguigu.yygh.model.hosp.ApartmentInfo;
import com.atguigu.yygh.model.hosp.Order;
import com.atguigu.yygh.model.user.StudentDetail;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.vo.hosp.OrderSearchVo;
import com.atguigu.yygh.vo.hosp.OrderVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jscq.cmn.client.DictFeignClient;
import com.jscq.yygh.user.mapper.OrderMapper;
import com.jscq.yygh.user.mapper.StudentDetailMapper;
import com.jscq.yygh.user.service.OrderService;
import com.jscq.yygh.user.service.StudentDetailService;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private DictFeignClient dictFeignClient;


    @Override
    public void updateStatus(String id, Integer status) {
        //获得订单

        Order order = this.getById(id);
        //设置修改的值
        order.setStatus(status);
        order.setUpdateTime(new Date());
        this.save(order);

    }

    @Override
    public IPage<Order> selectPage(Page<Order> page, OrderSearchVo orderVo) {
        QueryWrapper<Order> wrapper=new QueryWrapper<>();
        String stuCode = orderVo.getStudentId();
        String stuName = orderVo.getName();
        String crateTime = orderVo.getCreateTimeBegin();
        String endTime = orderVo.getCreateTimeEnd();
        Integer status = orderVo.getStatus();


        if (!StringUtils.isEmpty(stuCode)){
            wrapper.like("student_id",stuCode);
        }
        if (!StringUtils.isEmpty(stuName)){
            wrapper.like("name",stuName);
        }
        if (!StringUtils.isEmpty(crateTime)) {
            wrapper.gt("create_time",crateTime);
        }
        if (!StringUtils.isEmpty(endTime)) {
            wrapper.lt("create_time",endTime);
        }if (!StringUtils.isEmpty(status)) {
            wrapper.eq("status",status);
        }
        Page<Order> orderPage = baseMapper.selectPage(page, wrapper);
        return orderPage;
    }
}
